package com.qk.server.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.qk.common.PageResult;
import com.qk.entity.Role;
import com.qk.mapper.RoleMapper;
import com.qk.server.RoleServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class RoleServerImpl implements RoleServer {
    @Autowired
    private RoleMapper roleMapper;
    @Override
    public PageResult<Role> findRoleByList(String name, String label, Integer page, Integer pageSize) {
        //1.输入参数
        PageHelper.startPage(page,pageSize);
        //2.查询
        List<Role> roles = roleMapper.selectRoleByList(name, label);
        //3.封装
        Page<Role> pageInfo = (Page) roles;
        return new PageResult<>(pageInfo.getTotal(),pageInfo.getResult());
    }

    @Override
    public void deleteById(Integer id) {
        roleMapper.delRoleById(id);
    }

    @Override
    public void addRole(Role role) {
        role.setCreateTime(LocalDateTime.now());
        role.setUpdateTime(LocalDateTime.now());
        roleMapper.insert( role);
    }

    @Override
    public Role findRoleById(Integer id) {
        Role role=roleMapper.selectRoleById(id);
        return role;
    }

    @Override
    public void updateRole(Role role) {
        role.setUpdateTime(LocalDateTime.now());
        roleMapper.updateRole(role);
    }

    @Override
    public List<Role> findRoleAll() {
        return roleMapper.selectRoleAll();
    }
}
